package com.sunlg.smarthome.ui.environment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunlg.smarthome.R;
import com.sunlg.smarthome.data.entity.EnvirDevice;

import java.util.List;

/**
 * Created by sunlg on 2017/5/12.
 */

public class EnvriDeviceAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private List<EnvirDevice> envirDeviceList;

    public EnvriDeviceAdapter(Context context, List<EnvirDevice> envirDeviceList) {
        this.mContext = context;
        this.envirDeviceList = envirDeviceList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_envir_device, parent, false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        EnvirDevice device = envirDeviceList.get(position);

        viewHolder.tvDesc.setText(device.getDescription());
        if(device.getType() == 0) {
            viewHolder.tvType.setText("DHT11");
        }else if(device.getType() == 1){
            viewHolder.tvType.setText("DS18B20");
        }

    }

    @Override
    public int getItemCount() {
        return envirDeviceList.size();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder{

        TextView tvDesc;
        TextView tvType;

        public ItemViewHolder(View itemView) {
            super(itemView);
            tvDesc = (TextView)itemView.findViewById(R.id.tv_desc);
            tvType = (TextView)itemView.findViewById(R.id.tv_device_type);
        }
    }
}
